var javascripts  = require('../javascript-config.js')
var gulp         = require('gulp')
var changed      = require('gulp-changed')
var uglify		   = require('gulp-uglify')
var concat       = require('gulp-concat')
var notify       = require('gulp-notify')
var rename       = require('gulp-rename')
var path         = require('path')
var gulpIf       = require('gulp-if')
var argv         = require('yargs').argv;



global.jsTaskObj = {};
for (var i in javascripts.module) {
  global.jsTaskObj['js_'+i] = jsTask(javascripts.module[i]);
}


function jsTask(moduleName){
  return function() {
    if (argv.prod) {
      var dev = true;
    }
    return gulp.src(moduleName.paths)
      .pipe(changed(moduleName.exportPath))
      .pipe(concat(moduleName.contactName))
      .pipe(rename({ suffix: '.min' }))
      .pipe(gulpIf(dev, uglify()))
      .pipe(gulp.dest(moduleName.exportPath))
      .pipe(notify({ message: javascripts.message}))        
  };
}

global.jsTaskNameArray = [];
for (var j in global.jsTaskObj) {
  global.jsTaskNameArray.push(j)
  gulp.task(j, global.jsTaskObj[j])
}

module.exports = global.jsTaskObj;












